package com.blandware.atleap.webapp.taglib.core.menu.context;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

/**
 * <p>Renders label for menu item. This tag is used to render additional label
 * for context menu item, which must not appear on page.
 * <br />
 * This tag is only valid when nested within <em>itemEnabled</em> or
 * <em>itemDisabled</em> tag.
 * </p>
 * <p/>
 * <p><a href="MenuItemLabelTag.java.html"><i>View Source</i></a></p>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.4 $ $Date: 2006/08/03 10:08:25 $
 * @see ItemTag
 * @see ItemLinkTag
 * @jsp.tag name="itemLabel"
 * body-content="scriptless"
 */
public class ItemLabelTag extends SimpleTagSupport {

	/**
	 * Creates new instance of ItemEnabledTag
	 */
	public ItemLabelTag() {
	}

    /**
     * Processes the tag
     *
     * @throws JspException
     * @throws IOException
     */
	public void doTag() throws JspException, IOException {
		// search for parent ItemPart
		ItemPart part = (ItemPart) findAncestorWithClass(this, ItemPart.class);
		if ( part == null ) {
			throw new JspTagException("This tag is only valid when nested within 'itemEnabled' or 'itemDisabled' tag");
		}

		if ( part.getRenderingFlag() == ItemPart.FLAG_RENDER_TO_MENU ) {
			// obtain and invoke body content
			JspFragment body = getJspBody();
			if ( body != null ) {
				body.invoke(null);
			}
		}

	}

}
